from rest_framework import serializers
from .models import CourseCategory, Teacher, Course, CourseLesson, CourseChapter


class CourseCategoryModelSerializer(serializers.ModelSerializer):
    """课程分类的序列化器"""
    class Meta:
        model = CourseCategory
        fields = ["id","name"]


class CourseTeacherModelSerializer(serializers.ModelSerializer):
    """课程所属老师的序列化器"""
    class Meta:
        model = Teacher
        fields = ["name", "title", "signature", "image", "brief"]

class CourseModelSerializer(serializers.ModelSerializer):
    """课程信息的序列化器"""
    teacher = CourseTeacherModelSerializer()  # 老师 1： 多课程
    # teacher = CourseTeacherModelSerializer(many=True)  # 老师 1： 多课程

    class Meta:
        model = Course
        fields = ["id", "name", "course_img", "course_video","students", "lessons", "pub_lessons", "price", "teacher", "lesson_list"]

class CourseRetrieveModelSerializer(serializers.ModelSerializer):
    """课程详情页的序列化器"""
    teacher = CourseTeacherModelSerializer()
    class Meta:
        model = Course
        fields = ["id", "name", "course_img", "course_video","students", "lessons", "pub_lessons", "price", "teacher", "level_text", "brief", "attachment_path"]


class CourseLessonSerializer(serializers.ModelSerializer):
    class Meta:
        model = CourseLesson
        fields = ["id","name","duration", "free_trail"]



class CourseChapterModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = CourseChapter
        fields = ["chapter", "name", "summary", "lesson_list"]










